/*****************************************************************************/
/*      (c) Copyright 2006 Rapid Deployment Software - See License.txt       */
/*****************************************************************************/
/*                                                                           */
/*                       BACKEND MAIN PROGRAM                                */
/*                                                                           */
/*****************************************************************************/

/******************/
/* Included files */
/******************/

#include <time.h>

#ifdef ELINUX
# include <unistd.h>
# ifdef EBSD
#  include <limits.h>
# endif
#endif

#ifdef EWINDOWS
# include <windows.h>
# ifdef EBORLAND
#  include <float.h>
# else
#  include <sys\types.h>
#  include <sys\stat.h>
#  ifndef ELCC
#   include <i86.h>
#   include <bios.h>
#   include <graph.h>
#  endif
# endif
#endif

#include "global.h"

/**********************/
/* Imported variables */
/**********************/

#ifdef EWINDOWS
extern unsigned default_heap;
#endif
#ifdef EXTRA_STATS
extern int bad_samples;
extern int mouse_ints;

extern long a_miss;
extern long a_hit;
extern long a_too_big;
extern long bytes_allocated;
extern long max_bytes_allocated;

extern unsigned recycles;
#endif

/**********************/
/* Exported variables */
/**********************/

int clk_tck;
int clocks_per_sec;

/*******************/
/* Local variables */
/*******************/


/**********************/
/* Declared functions */
/**********************/


/*********************/
/* Defined functions */
/*********************/

#ifdef EXTRA_STATS
void Stats()
/* print execution statistics */
{
    int i;
    FILE *opfile;

    StorageStats();
    printf("bytes of extra storage allocated\n");
    printf("   maximum: %d\n", max_bytes_allocated);
    printf("   current: %d\n", bytes_allocated);
    printf("storage cache  hits: %d\n", a_hit);
    printf("             misses: %d\n", a_miss);
    printf("            too big: %d\n", a_too_big);
    printf("           recycles: %d\n", recycles);
    printf("unused mouse interrupts: %d\n", mouse_ints);
    printf("bad time-profile samples: %d\n", bad_samples);
}
#endif

void be_init()
/* Main routine for Interpreter back end */
{
    char *p, *temp;
    int i;
    long c;

    clocks_per_sec = CLOCKS_PER_SEC;
#ifdef ELCC
    clk_tck = CLOCKS_PER_SEC;
#else
# ifdef CLK_TCK
    clk_tck = CLK_TCK;
# else
    clk_tck = sysconf(_SC_CLK_TCK);
# endif
#endif

#ifdef EWINDOWS
# ifdef EBORLAND
    /* J.A. -> Some Google research says that this stops Borland's floating-point
       exception handler. Supposedly, it causes problems in stuff like DirectX and
       OpenGL. */
    _control87(MCW_EM,MCW_EM);
# endif
#endif
}

